package com.xh.login.service;

import cn.hutool.core.util.ObjectUtil;
import com.xh.login.dao.UserDao;
import com.xh.login.entity.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author 张园园
 */
@Service
public class UserService {

    @Resource
    /*
      注入userDao
     */
    private UserDao userDao;

    public User login(User user) {
        if (user == null) {
            throw new IllegalArgumentException("参数不能为空");
        }
        return userDao.login(user);
    }
    public List<User> index(){
        return  userDao.index();
    }
    public Integer addUser(User user){
        return userDao.addUser(user);
    }
    /**
     * 注册功能
     * @param user
     * @return
     */
    public Object register(User user) {
        if (ObjectUtil.isNull(user)) {
            throw new IllegalArgumentException("参数不能为空");
        }

        Integer register = userDao.register(user);

        if (register <= 0){
            throw new RuntimeException("添加失败");
        }

        return register;
    }
    public Integer deleteUser(Integer id){
        if (id ==null){
            System.out.println("删除失败");
        }
        return userDao.deleteUser(id);
    }public Integer updateUser(User user){
        if (user==null){
            System.out.println("修改失败");
        }
        return  userDao.updateUser(user);
    }
}
